package org.lds.message.center.common.model.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.lds.message.center.common.util.JsonUtil;

import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class EmailRequest extends CommonRequest {

    /**
     * 是否携带附件 默认为false
     */
    private boolean multipart = false;

    /**
     * 附件 允许为空
     */
    private List<Attachment> attachments;

    /**
     * 收件人邮箱 必填
     */
    private String[] to;

    /**
     * 抄送人邮箱 可选
     */
    private String[] cc;

    /**
     * 密送人邮箱 可选
     */
    private String[] bcc;

    /**
     * 邮件标题 必填
     */
    private String subject;

    /**
     * 邮件正文 可选
     */
    private String text;

    /**
     * 调用方应用名称 可选
     */
    private String appName;
    /**
     * 模板名称 可选
     */
    private String templateName;
    /**
     * 模板参数 可选
     */
    private Map<String, String> templateParam;

    /**
     * 是否是HTML正文 默认为false
     */
    private boolean html = false;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class Attachment {
        /**
         * 附件文件名 必填
         */
        private String filename;
        /**
         * 附件文件地址 必填
         */
        private String fileAddress;

        @Override
        public String toString() {
            return "{"
                    + "\"filename\":\""
                    + filename + '\"'
                    + ",\"fileAddress\":\""
                    + fileAddress + '\"'
                    + "}";
        }
    }

    @Override
    public String toString() {
        return "{"
                + "\"multipart\":"
                + multipart
                + ",\"attachments\":"
                + attachments
                + ",\"to\":"
                + JsonUtil.toJson(to)
                + ",\"cc\":"
                + JsonUtil.toJson(cc)
                + ",\"bcc\":"
                + JsonUtil.toJson(bcc)
                + ",\"subject\":\""
                + subject + '\"'
                + ",\"text\":\""
                + text + '\"'
                + ",\"html\":"
                + html
                + "}";
    }
}
